
function changeURLArg(url,arg,arg_val){ 
    var pattern=arg+'=([^&]*)'; 
    var replaceText=arg+'='+arg_val; 
    if(url.match(pattern)){ 
        var tmp='/('+ arg+'=)([^&]*)/gi'; 
        tmp=url.replace(eval(tmp),replaceText); 
        return tmp; 
    }else{ 
        if(url.match('[\?]')){ 
            return url+'&'+replaceText; 
        }else{ 
            return url+'?'+replaceText; 
        } 
    } 
    return url+'\n'+arg+'\n'+arg_val; 
} 

function toPage(pageNum, totalPage, bean) {
    if(pageNum == null) {
        pageNum = 1;
    }

    if(pageNum <= 0) {
    	alert("当前已经是第一页");
        return;
    }

    if(pageNum > totalPage) {
    	alert("当前已经是最后一页");
        return;
    }

    var form = document.getElementById(bean + "Form");
   	form.action = changeURLArg(window.location.href, "pageNum", pageNum);
//    form.action = window.location.pathname + "?pageNum=" + pageNum;
//    form.action = "../" + bean + "/list?pageNum=" + pageNum;
    form.submit();
}

function pageSizeChange(bean) {
	var form = document.getElementById(bean + "Form");
   	form.action = changeURLArg(window.location.href, "pageNum", 1);
    form.submit();
}


function initPageSize(pageSize){
	
//	var select = document.getElementById("pageSize");
//	
//	for(var i = 0; i < select.length; i++) {
//		var op = select[i];
//		if(op.value == pageSize) {
//			$(op).attr("selected", "selected");
//		} else {
//			$(op).removeAttr("selected");
//		}
//	}
}

$(function(){
	initPageSize($("#pageSizeHidden").val());
});